/*

Author   : chaos

FileName : obj_ptr_array.cpp

Date     : 15/08/17 15:18:39

*/
#include <iostream>
#include <cstring>
using namespace std;

class person
{
    protected:
        char name[10];
    public:
        person(const char * iname)
        {strcpy(name,iname);}
        virtual ~person() {cout << "~person is called." << endl;}
        virtual void who_are_you() = 0;
};

class student :public person
{
    private:
        char major_in[15];
    public:
        student(const char* iname,const char * major):person(iname)
         { strcpy(major_in,major); }
        void who_are_you()
        {
            cout << "My name is " << name << " .";
            cout << "I major in " << major_in << " !" << endl;
        }
        ~student(){cout << "~student() is called. " << endl;}
};

class teacher:public person
{
    private:
        char teach_for[15];
    public:
        teacher(const char * iname,const  char * teach):person(iname)
    {strcpy(teach_for,teach);}

        void who_are_you()
        {
            cout << "My name is " << name << " .";
            cout << "I am a" << teach_for << "teacher !" << endl;
        }

        ~teacher(){cout << "~teacher() is called." << endl;}
};

int main(int argc ,char *argv[])
{
    person * pPerArr[5];

    pPerArr[0] = new student("John","mathematics");
    pPerArr[1] = new teacher("Mary","Chinese");
    pPerArr[2] = new teacher("Joe","chemical");
    pPerArr[3] = new student("Bill","physics");
    pPerArr[4] = new teacher("May","English");

    for(int i = 0; i < 5; i++ )
    {
        pPerArr[i]->who_are_you();
        delete pPerArr[i];

    }
    return 0;
}
